package repository

import (
	"context"

	"gitee.com/thewalkers/refactoring-code/model"
	"github.com/jmoiron/sqlx"
	"go.uber.org/zap"
)

// MysqlSalariedClassificationRepository is data/repository implementation
// of service layer EmployeeRepository
type MysqlSalariedClassificationRepository struct {
	DB *sqlx.DB
}

// NewHourlyClassificationRepository is a factory for initializing Employee Repository
func NewSalariedClassificationRepository(db *sqlx.DB) model.ChangeSalariedTransactionRepository {
	return &MysqlSalariedClassificationRepository{
		DB: db,
	}
}

// Update Salaried Classification by Payment Classification id
func (m *MysqlSalariedClassificationRepository) Update(ctx context.Context, s *model.SalariedClassification) error {
	query := `UPDATE salaried_classification SET salary = ? WHERE payment_classification_id = ?`
	if _, err := m.DB.Exec(query, s.Salary, s.PaymentClassificationID); err != nil {
		zap.L().Error("repository cound not update salaried classification with err: ", zap.Error(err))
		return err
	}

	return nil
}
